//
//  CustomPageControl.m
//  CBSystem
//
//  Created by Ryan Yuan on 12-7-6.
//  Copyright (c) 2012年 Yulong. All rights reserved.
//

#import "CustomPageControl.h"

#define kNameOfActiveImage  @"dot_active.png"
#define kNameOfNormalImage  @"dot_normal.png"

@implementation CustomPageControl

- (void) setCurrentPage:(NSInteger)page {
	[super setCurrentPage:page];

    UIImage *imgActive = [UIImage imageNamed:kNameOfActiveImage];
    UIImage *imgNormal = [UIImage imageNamed:kNameOfNormalImage];

	for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++) 
	{
		UIImageView* subview = [self.subviews objectAtIndex:subviewIndex];
		
		CGRect oFrame = subview.frame;
		[subview setFrame:CGRectMake(oFrame.origin.x, oFrame.origin.y, 6.0, 6.0)];
		
		if (subviewIndex == page) 
			[subview setImage:imgActive];
		else 
			[subview setImage:imgNormal];
	}
}

- (void) setNumberOfPages:(NSInteger)pages 
{
	[super setNumberOfPages:pages];
	
	UIImage *imgNormal = [UIImage imageNamed:kNameOfNormalImage];
    
	for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++) 
	{
		UIImageView* subview = [self.subviews objectAtIndex:subviewIndex];
		
		CGRect oFrame = subview.frame;
		[subview setFrame:CGRectMake(oFrame.origin.x, oFrame.origin.y, 6.0, 6.0)];
		
		[subview setImage:imgNormal];
	}
}



#pragma mark - Catch pagecontrol click event
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { // 点击事件
    return ;
}

//- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { // 点击事件
//    [super endTrackingWithTouch:touch withEvent:event];
//    [self updateDots];
//}
//- (void)updateDots { // 更新显示所有的点按钮
//    NSArray *subview = self.subviews;  // 获取所有子视图
//    
//    UIImage *imgActive = [UIImage imageNamed:kNameOfActiveImage];
//    UIImage *imgNormal = [UIImage imageNamed:kNameOfNormalImage];
//    
//    for (NSInteger i = 0; i < [subview count]; i++)
//    {
//        UIImageView *dot = [subview objectAtIndex:i];  // 以下不解释, 看了基本明白
//        dot.image = self.currentPage == i ? imgActive : imgNormal;
//    }
//}
@end
